/**
 * 
 */
var innerPaginationService = angular.module('innerPaginationService', []);

innerPaginationService.factory('innerPagination', function() {
	var innerPagination = {};
	
	innerPagination.setData = function(data) {
		var start = 1;
		var end = data.pages;
		
		if (data.currentPage > 5) {
			start = data.currentPage - 5;
		}
		if (data.currentPage + 5 < data.pages) {
			end = data.currentPage + 5;
		}
		
		var pageNums = [];
		for (var i = start; i <= end; i++) {
			pageNums[i-start] = i;
		}
		data.pageNums = pageNums;
		innerPagination.data = data;
	};
	
	innerPagination.setFun = function(fun) {
		innerPagination.fun = fun;
	};
	
	innerPagination.nextPage = function() {
		if (innerPagination.data.currentPage >= innerPagination.data.pages) return;
		innerPagination.data.start = innerPagination.data.start + innerPagination.data.count;
		innerPagination.data.currentPage = innerPagination.data.currentPage + 1;
//		innerPagination.fun();
	};
	
	innerPagination.lastPage = function() {
		if (innerPagination.data.currentPage == 1) return;
		innerPagination.data.start = innerPagination.data.start - innerPagination.data.count;
		innerPagination.data.currentPage = innerPagination.data.currentPage - 1;
//		innerPagination.fun();
	};
	
	innerPagination.goPage = function(selNum) {
		innerPagination.data.currentPage = selNum;
		innerPagination.data.start = (selNum - 1) * innerPagination.data.count;
//		innerPagination.fun();
	};
	
	return innerPagination;
});